﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Itfort
{
	/// <summary>
	/// 对象转换扩展。
	/// </summary>
	public static class ObjectConverterExtensions
	{
		/// <summary>
		/// 将object转换成T类型的实例对象。
		/// </summary>
		/// <typeparam name="T">目标对象类型。</typeparam>
		/// <param name="sourceObject">来源对象。</param>
		/// <returns></returns>
		public static T Convert2<T>(this Object sourceObject)
		{
			return ObjectConverter.Convert<T>(sourceObject);
		}

		/// <summary>
		/// 将Entity列表转换成T类型列表。
		/// </summary>
		/// <typeparam name="TSource">来源对象类型。</typeparam>
		/// <typeparam name="TTarget">目标对象类型。</typeparam>
		/// <param name="sourceList">来源列表。</param>
		/// <returns></returns>
		public static List<TTarget> Convert2<TSource, TTarget>(this IList<TSource> sourceList)
		{
			return ObjectConverter.Convert<TSource, TTarget>(sourceList);
		}

		/// <summary>
		/// 将Entity列表转换成T类型列表。
		/// </summary>
		/// <typeparam name="T">目标对象类型。</typeparam>
		/// <param name="sourceList">来源列表。</param>
		/// <returns></returns>
		public static List<T> Convert2<T>(this IEnumerable sourceList)
		{
			return ObjectConverter.Convert<T>(sourceList);
		}
	}
}
